package cn.kgc.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import cn.kgc.mapper.CompanyMapper;
import cn.kgc.pojo.Auditstate;
import cn.kgc.pojo.Company;
import cn.kgc.service.CompanyService;
import cn.kgc.util.Page;
import com.alibaba.dubbo.config.annotation.Service;

/**
* 描述： 服务实现层接口
* @author 
* @date 2018/03/05
*/
@Service
public class CompanyServiceImpl implements CompanyService {
	@Resource
	private CompanyMapper companyMapper;
 	
 	/**
    * 描述：根据Id获取Company对象
    * @param id
    */
    public Company findById(Serializable id){
    	return companyMapper.findById(id);
    }
    /**
    * 描述：获取所有的Company对象
    */
    public List<Company> findAll(){
    	return companyMapper.findAll();
    }

	/**
    * 描述：新增保存Company对象
    */
    public int save(Company company){
    	return  companyMapper.save(company);
    }

	@Override
	public List<Auditstate> selectAllAuditstate() {
		return null;
	}

	/**
    * 描述：根据Id删除Company对象
    * @param id
    */
    public int delete(Serializable id){
    	return  companyMapper.delete(id);
    }

	@Override
	public int update(Integer companyId, Integer auditState) {
		return 0;
	}

	@Override
	public String seleceEmail(Integer companyId) {
		return null;
	}

	/**
    * 描述：更新Company对象
    */
    public int update(Company company){
    	return  companyMapper.update(company);
    }

	@Override
	public Page queryByPage(String companyName, Integer index, Integer size) {
		return null;
	}

	@Override
	public int getCount(String companyName) {
		return 0;
	}

	/**
     * 根据不确定的条件，动态查询
     */
    public List<Company> query(Object params){
    	return  companyMapper.query(params);
    }
    
    /**
     * 根据不确定的条件，动态分页查询
     */
    public Page queryByPage(Object params, Page page){
    	int totalCount = companyMapper.getCount(params);
    	int totalPageCount = (totalCount-1)/page.getSize()+1;
    	if(page.getPageIndex()<1){
    		page.setPageIndex(1);
    	}else if(page.getPageIndex()>totalPageCount){
    		page.setPageIndex(totalPageCount);
    	}
    	page.setTotalCount(totalCount);
    	page.setTotalPage(totalPageCount);
		int firstRow=(page.getPageIndex()-1)*page.getSize();
    	List list = companyMapper.queryByPage(params,firstRow,page.getSize());
    	page.setList(list);
    	return page;
    	
    }

	@Override
	public Company getCompanyByCompanyName(String companyName) {
		return companyMapper.getCompanyByCompanyName(companyName);
	}

}
